<?php
namespace Rainrock\Framework\Controller;


use Rainrock\Framework\kernel\base\Auth;
use Rainrock\Framework\kernel\base\File;
use Rainrock\Framework\kernel\base\Jiami;
use Rainrock\Framework\kernel\base\CDate;
/**
*	管理首页（首页里的）
*/
class AdminhomeController extends AuthController{
	

	/**
	*	首页内容需要重写
	*/
	public function indexAction()
	{
		
		$div = $this->Label();
		$div->addCont($this->Label()->addCont('欢迎使用，'.TITLE.'')->setFontsize(20)->setPadding(15)->setPadding(20,'top'));
		$div->addCont(
			$this->Label()->addCss('wrap')->setMargin(10,'bottom')
				->addCont($this->Label('span')->setFontsize(12)->addCss('hui')->addCont('此首页可以在文件下自己'.ROOT_PACK.'/Controller/adminhome/AdminhomeController.php编写'))
		);
		
		$mdiv = $this->Label()->addStyle('min-height','400px')->addCss('flex')->setPadding(15)->setValign('flex-start')->addStyle('justify-content','center')->addStyle('flex-wrap','wrap');

		$mdiv2 = $this->homeItem('帮助', array(
			$this->Label('a')->addCont('进入我们的信呼官网。')->setHref(URLY)->setIsnew(true),
			$this->Label('a')->addCont('框架帮助')->setHref(URLY.'view_framework.html')->setIsnew(true),
			$this->Label('a')->addCont('信呼OA')->setHref(URLY.'view_down.html')->setIsnew(true)
		));
		$mdiv->addCont($mdiv2);
		
		$barr = $this->moreHomeItem();
		if(is_array($barr))foreach($barr as $vs)$mdiv->addCont($vs);
		
		if(Auth::$TYPE==2){
			$itema 	= array();
			$paths  = ''.ROOT_PACK.'/logs/list';
			$files 	= File::getFolder($paths, null, array('limit'=>10));
			foreach($files as $file){
				$filev	 = $paths.'/'.$file;
				$optdt   = CDate::stringdt(date('Y-m-d H:i:s',filectime($filev)));
				$itema[] = $this->Label()
					->setonClick('js.open(\'?m=adminmanage&a=syslog&file='.Jiami::base64encode($filev).'\')')
					->addCont($file)
					->setFontcolor(($this->contain($filev, 'error_'))?'red':'')
					->addCont($this->Label('span')->addCont('(')->addCont($optdt)->addCont(')')->setFontsize(12)->addCss('hui'));
			}
			$mdiv2 = $this->homeItem('日志文件', $itema, 'javascript:addtabs({name:\'日志文件\',url:\'adminmanage,filelist,path='.Jiami::base64encode(''.PACKPATH.'/logs/list').'\'})')->setWidth(400);
			$mdiv->addCont($mdiv2);
		}

		if(Auth::$TYPE==2 && $this->m('syslog')->isInstall()){
			$rows = $this->m('syslog')->getall('1=1','*','id desc', 5);
			$itema = array();
			foreach($rows as $k=>$rs){
				$itema[] = $this->Label()
					->setonClick('js.openxiang(\'syslog\','.$rs['id'].')')->addCont('[')
					->addCont($rs['type'])
					->addCont(']')
					->addCont($rs['remark'])
					->setFontcolor(($rs['level']==3)?'red':'')
					->addCont($this->Label('span')->addCont('(')->addCont(CDate::stringdt($rs['optdt']))->addCont(')')->setFontsize(12)->addCss('hui'));
			}
			$mdiv2 = $this->homeItem('系统日志', $itema, 'javascript:ind.listopen(\'syslog\',\'系统日志\')')->setWidth(400);
			$mdiv->addCont($mdiv2);
		}
		
		$div->addCont($mdiv);
		$div->addCont(PublicViews::Footer());
		return $div->show();
	}
	
	public function homeItem($title, $item, $more='')
	{
		$mdiv2 = $this->Label()->setAlign('left')->setMargin(15,'right')->setMargin(15,'bottom')->setWidth(320)->addCss('panel');
		$ismore = '';
		if($more){
			$ismore = $this->Label('a')->addCont('更多&gt;')->setHref($more)->addStyle('float','right');
		}
		$mdiv2->addCont(
			$this->Label()->addCont($title)->addCss('panel-title')
			->addCont($ismore)
		);
		$sdiv = $this->Label()->addCss('list-group');
		if($item)foreach($item as $items){
			$sdiv->addCont($this->Label()->addCss('list-group-item')->addCont($items));
		}
		$mdiv2->addCont($sdiv);
		return $mdiv2;
	}
	
	/**
	*	更多首页项目
	*/
	public function moreHomeItem()
	{
		
	}
}